package Player;
sub new
{
    my $class = shift;
    my $self = {
        name => shift,
        strength => shift,
        wit => shift,
        rep => shift,
        ally => shift,
        time => shift,
        immune => shift,
        alliance => [int(rand(4))],
        votes => [],
        inventory => []
    };
    bless $self, $class;
    return $self;        
}
sub getStrength
{
    my ($self) = @_;
    return $self->{strength};    
}
sub getAlliance
{
    my ($self) = @_;
    return $self->{alliance};
}
sub getInventory
{
    my($self) = @_;
    return $self->{inventory};
}
sub getWit
{
    my ($self) = @_;
    return $self->{wit};
}
sub getTime
{
    my ($self) = @_;
    return $self->{time};
}
sub getRep
{
    my ($self) =  @_;
    return $self->{rep};
}
sub getAlly
{
    my ($self) = @_;
    return $self->{ally};    
}
sub getName
{
    my ($self) = @_;
    return $self->{name};
}
sub joinAlliance
{
    my ($self, $person) = @_;
    my $present = 1;
    foreach my $temp (@{$self->{alliance}})
    {
        if($temp == @{$person->getAlliance}[0])
        {
            $present = 0;
        }
    }
    if($present)
    {
        @{$self->{alliance}} = (@{$self->{alliance}}, @{$person->getAlliance}[0]);
    }
    return @{$self->{alliance}};
}
sub breakAlliance
{
    my ($self, $person) = @_;
    my $present = 1;
    my @temp;
    foreach my $temp (@{$self->{alliance}})
    {
        if($temp != @{$person->getAlliance}[0])
        {
            push(@temp, $temp)
        }
    }
    @{$self->{alliance}} = @temp;
    return @{$self->{alliance}};
}
sub addNullAlliance
{
    my ($self) = @_;
    @{$self->{alliance}} = (5);
    return @{$self->{alliance}};
}
sub addVote
{
    my ($self, $vote) = @_;
    push(@{$self->{votes}}, $vote);
    return @{$self->{votes}};
}
sub removeVote
{
    my ($self, $vote) = @_;
    my @temp;
    foreach my $temp (@{$self->{votes}})
    {
        if($temp != $vote)
        {
            push(@temp, $temp)
        }
    }
    @{$self->{votes}} = @temp;
    return @{$self->{votes}};
}
sub getVotes
{
    my ($self) = @_;
    return @{$self->{votes}};
}
sub clearVotes
{
    my ($self) = @_;
    undef @{$self->{votes}};
    return @{$self->{votes}};
}
sub getVote
{
    my ($self) = @_;
    my $vote = @{self->{votes}}[int(rand(@{$self->{votes}}))];
    undef @{$self->{votes}};
    return $vote;
}
sub setName
{
    my ($self, $name) = @_;
    $self->{name} = $name;
    return $self->{name};
}
sub gets
{
    my ($self, $obj, $val) = @_;
    if($obj eq "immunity idol") {$self->{immune} = 1;}
    if (@_) 
    { 
        my %inv_hash = @{$self->{inventory} }; 
        if($inv_hash{$obj})
        {
            $inv_hash{$obj}++;
        }
        else
        {
            $inv_hash{$obj} = $val;
        }
        @{$self->{inventory}} = %inv_hash;
    }
    return @{$self->{inventory}};
}
sub loses
{
    my($self, $obj, $val) = @_;
    if($obj eq "immunity idol") {$self->{immune} = 0;}
    my %inv_hash = @{$self->{inventory} };
    $inv_hash{$obj} -= $val;
    if($inv_hash{$obj} <= 0)
    {
        delete($inv_hash{$obj});
    }
    @{$self->{inventory}} = %inv_hash;
    return @{$self->{inventory}};
}
sub incStrength
{
    my ($self, $strength) = @_;
    $self->{strength} += $strength;
	if($strength > 1000){$strength = 1000;}
	if($strength < 0){$strength = 0;}
    return $self->{strength};
}
sub incAlly
{
    my ($self, $ally) = @_;
    if(($ally + $self->{ally}) < 1)
    {
        $self->{ally} = 1;
    }
    elsif(($ally + $self->{ally}) > 9)
    {
        $self->{ally} = 10;
    }
    else
    {
    $self->{ally} += $ally;
    }
    return $self->{ally};
}
sub setTime
{
    my ($self, $time) = @_;
    $self->{time} = $time;
    return $self->{time};
}
sub isImmune
{
    my ($self) = @_;
    return $self->{immune};
}
sub incRep
{
    my ($self, $rep) = @_;
    if(($rep + $self->{rep}) < 1)
    {
        $self->{rep} = 1;
    }
    elsif(($rep + $self->{rep}) > 999)
    {
        $self->{rep} = 1000;
    }
    else
    {
    $self->{rep} += $rep;
    }
    return $self->{rep};
}
sub incWit
{
    my ($self, $wit) = @_;
    $self->{wit} += $wit;
	if($wit > 1000){$wit = 1000;}
	if($wit < 0){$wit = 0;}
    return $self->{strength};
}
1;
    
